package com.sky.controller;

import com.sky.anotion.validator.AddGroup;
import com.sky.anotion.validator.UpdateGroup;
import com.sky.constant.MessageConstant;
import com.sky.dto.common.PageRequest;
import com.sky.dto.common.ParamsID;
import com.sky.dto.common.QueryParams;
import com.sky.entity.Instructor;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.InstructorService;
import com.sky.vo.InstructorInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/instructor")
@Slf4j
public class InstructorController {
    @Autowired
    private InstructorService instructorService;

    /**
     * 分页查询 获取所有的用户信息
     * @param queryParams
     * @return
     */
    @PostMapping("/getAllInstructor")
    public Result<PageResult> getAllInstructor(@RequestBody PageRequest<QueryParams> queryParams) {
        log.info("获取所有的用户信息{}",queryParams);
        PageResult pageResult = instructorService.getAllInstructor(queryParams);
        return Result.success(pageResult, MessageConstant.OK_MESSAGE);
    }
    /**
     * 增加用户信息
     */
    @PostMapping("/addInstructor")
    public Result<String> addInstructor(@RequestBody @Validated(AddGroup.class) InstructorInfoVO instructorAddDTO) {
        log.info("增加用户信息:{}", instructorAddDTO);
        instructorService.addInstructor(instructorAddDTO);
        return Result.success(null, MessageConstant.OK_MESSAGE);
    }
    /**
     * 修改用户信息
     */
    @PostMapping("/editInstructor")
    public Result<String> editInstructor(@RequestBody @Validated(UpdateGroup.class) InstructorInfoVO instructorInfoVO) {
        log.info("修改用户信息:{}", instructorInfoVO);
        instructorService.editInstructor(instructorInfoVO);
        return Result.success(null, MessageConstant.OK_MESSAGE);
    }
    /**
     * 删除用户信息
     */
    @PostMapping("/deleteInstructor")
    public Result<String> deleteInstructor(@RequestBody ParamsID paramsIDs) {
        log.info("删除用户信息:{}", paramsIDs);
         instructorService.deleteInstructor(paramsIDs);
        return Result.success(null,MessageConstant.OK_MESSAGE);
    }
    /**获取一级部门的负责人信息*/
    @PostMapping("/getOnePeople")
    public Result<List<Instructor>> getOnePeople(@RequestBody ParamsID paramsID,@RequestParam(defaultValue = "10001") String type) {
        log.info("获取一级部门的负责人信息:{}", paramsID);
        List<Instructor> instructor = instructorService.getOnePeople(paramsID,type);
        return Result.success(instructor, MessageConstant.OK_MESSAGE);
    }
}
